// pages/search.js
import { request } from "../../utlis/asyncWx"
// import regeneratorRuntime from "../../lib/runtime/runtime"
Page({
  data: {
    resultGoods: [],
    isFocus: false,
    inputValue: ''
  },
  TimeId: -1,
  onLoad: function (options) {

  },
  // 输入东西
  handleInput(e) {
    console.log(e)
    const { value } = e.detail
    if (!value.trim()) {
      this.setData({ resultGoods: [], isFocus: false })
      return
    }
    this.setData({ isFocus: true })
    // 定时器
    clearTimeout(this.TimeId)
    this.TimeId = setTimeout(() => {
      this.qsearch(value)
    }, 1000);
  },
  cancelBtn() {
    this.setData({ resultGoods: [], inputValue: '' })
  },
  async qsearch(query) {
    const res = await request({ url: "goods/qsearch", data: { query } })
    console.log(res);
    this.setData({
      resultGoods: res.data.message
    })
  }
})